package exercises.leetcode;

import java.util.HashSet;

/**
 * <a href="">
 * </a>
 *
 * <p><span color="#87CEEB">描述:</span>
 *
 * @author or2
 * @date 2021年11月14日 时间: 16:27
 */
public class No128 {
    public int longestConsecutive(int[] nums) {
        var set = new HashSet<Integer>();
        for (int num : nums) set.add(num);

        int res = 0;

        for (Integer num : set) {
            if (set.contains(num - 1)) continue;

            int lenCur = 1;
            while (set.contains(num + lenCur)) lenCur++;

            res = Math.max(lenCur, res);
        }

        return res;
    }
}
